package com.mt.operation.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.common.constants.BaseErrorConstants;
import com.mt.operation.api.service.IAdvertisementPopupService;
import com.mt.operation.entity.AdvertisementPopupEntity;
import com.mt.operation.service.model.AdvertisementPopupServiceModel;

@Service
public class AdvertisementPopupServiceImpl implements IAdvertisementPopupService {

    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(AdvertisementPopupServiceImpl.class);

    @Autowired
    private AdvertisementPopupServiceModel advertisementPopupServiceModel;

    public ServiceResult<AdvertisementPopupEntity> findInfo(Map<String, Object> params) {
        // 查询用户信息
        ServiceResult<AdvertisementPopupEntity> result = null;
        // 该参数标识前段是否需要权限数据
        try {
            result = advertisementPopupServiceModel.selectInfo(params);
        } catch (Exception e) {
            LOGGER.error("[AdvertisementPopupServiceImpl][findInfo]：query findInfo occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询详情错误");
        }
        return result;
    }

    public ServiceResult<List<AdvertisementPopupEntity>> findList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        ServiceResult<List<AdvertisementPopupEntity>> result = new ServiceResult<List<AdvertisementPopupEntity>>();
        try {
            result = advertisementPopupServiceModel.selectList(params, pagerInfo);
        } catch (Exception e) {
            LOGGER.error("[AdvertisementPopupServiceImpl][findList]：query findList occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询列表错误");
        }

        return result;
    }

    public ServiceResult<Integer> doInsert(AdvertisementPopupEntity advertisementPopupEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = advertisementPopupServiceModel.insert(advertisementPopupEntity);
        } catch (Exception e) {
            LOGGER.error("[AdvertisementPopupServiceImpl][doInsert]：query doInsert occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doUpdateRelate(AdvertisementPopupEntity advertisementPopupEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = advertisementPopupServiceModel.updateRelate(advertisementPopupEntity);
        } catch (Exception e) {
            LOGGER.error("[AdvertisementPopupServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "编辑信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doDeleteById(Integer advertisementPopupId) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = advertisementPopupServiceModel.deleteByPrimaryKey(advertisementPopupId);
        } catch (Exception e) {
            LOGGER.error("[AdvertisementPopupServiceImpl][doDeleteById]：query doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doUpdate(AdvertisementPopupEntity advertisementPopupEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = advertisementPopupServiceModel.updateByPrimaryKeySelective(advertisementPopupEntity);
        } catch (Exception e) {
            LOGGER.error("[AdvertisementPopupServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "更新信息错误.");
        }
        return result;
    }

}
